/*
 * @Author: huangtianyang 916072572@qq.com
 * @Date: 2023-07-03 17:34:28
 * @LastEditors: huangtianyang
 * @LastEditTime: 2023-08-24 16:07:48
 * @FilePath: \cxl-h5\src\pages\report\newEnergy\index.ts
 */
import { getReportBatteryDetailed, vinParse } from '@/apis/report'
import DialGaugeChart from '@/utils/chart/dialGaugeChart'
import { nextTick, onMounted, onUnmounted, reactive, ref } from 'vue'
import { useRoute } from 'vue-router'
import scrollIntoView from 'smooth-scroll-into-view-if-needed'
import Styler from 'stylefire'
import { animate } from 'popmotion'

import icon_dianchi from '@/assets/images/icon_dianchi.png'
import icon_chongfangdian from '@/assets/images/icon_chongfangdian.png'
import icon_xingshi from '@/assets/images/icon_xingshi.png'
import icon_guzhang from '@/assets/images/icon_guzhang.png'
import useWeixinSdk from '@/utils/WXSdk'
import { rule_1 as batteryHealthScore } from '@/utils/config'
import { NewEnergyScore } from '@/utils/newEnergyScore'
import { dayToDate } from '@/utils'

//基本信息
interface objParams {
    value: number | string
    status: number //1异常 0 正常
    label: string //
    icon?: null | number
}
interface basicParams {
    [propName: string]: any[] | string | objParams
}
interface columnParams {
    key: string // key
    blockClassName: string //最外层的classname
    bodyClassName: string //内容部分的classname
    name: string //标题
    icon: boolean //是否显示 问号Icon
    hint: string //文本提示
    abnormal: boolean //是否展示异常项数据
    abnormalCount: number //异常项数
    spread: boolean //是否展开内容
}

export class NewEnergy {
    //报告过期
    reportExpire = ref(false)
    //报告是否加载完成
    reportLoad = ref(false)
    //默认显示水印
    watermarkVisible = ref(false)
    //是否显示返回顶部按钮
    goTopVisible = ref(false)
    //底部下载分享栏弹窗
    bottomFnVisible = ref(false)
    isShare = ref(false)
    fromCase = ref(false)
    reportType = ref('')
    reportId = ref('')
    vinParseId = ref('')
    baseInfo = reactive({
        brandLogo: '',
        generateTime: '',
        reportNo: '',
        vin: '',
        plateNo: '',
        licensePlateColor: '',
        models: '',
        brandname: '',
        orderNo: '',
        fuelType: '',
        displacement: '',
        listingTime: ''
    })
    //评分等级
    scoreHealthLevel = ['较好', '一般', '较差', '差']
    //电池评分
    score: any[] = reactive([])
    BATTERY_Score_abnormal = ref(0)
    //续航下降
    declineRatio = ref('0%')
    //出险排查
    checkList = reactive([
        { icon: icon_dianchi, label: '电池健康度', value: 0, targetEle: '.battery-score-block' },
        { icon: icon_chongfangdian, label: '充放电数据', value: 0, targetEle: '.charge-discharge-block' },
        { icon: icon_xingshi, label: '行驶数据', value: 0, targetEle: '.run-block' },
        { icon: icon_guzhang, label: '故障分析', value: 0, targetEle: '.battery-safe-block' }
    ])
    //电池静态数据
    BATTERY_STATIC_DATA = reactive({
        fullChargedDrivingMile: '', // '参考续航里程',
        batteryManufacturer: '', // '电池厂商',
        rateCapacity: '', // '标称电池容量',
        packCode: '', // '电池包编码',
        rateMileage: '', // '标称续航里程',
        nominalEnergy: '', //'系统标称能量',
        manufacturerDate: '' //'生产日期'
    })
    //充放电数据
    CHARGE_DISCHARGE_DATA_abnormal = ref(0)
    CHARGE_DISCHARGE_DATA = reactive<basicParams>({
        firstChargeDate: '', // '首次充电时间',
        latestChargeDate: '', // '最后一次充电时间',
        totalChargeCount: '', // '总充电次数',
        // estimatedChargeCount: '', // '估计的充电次数',
        totalChargeSoc: '', //'总充电量以循环圈数累计',
        chaVoltDiffMean: '', // '充电电芯平均压差',
        fastRatio: '', // '快充占比',
        chaSocAvg: '', // '次均充入量',
        chaMaxTempMean: '', // '充电最高温度平均',
        chaMinTempMean: '', // '充电最低温度平均',
        chaStartSoc: '', // '充电最高频率下的起始SOC',
        chaEndSoc: '' //'充电最高频率下的截止SOC'
    })
    //行驶数据
    RUN_DATA_abnormal = ref(0)
    RUN_DATA = reactive<basicParams>({
        firstDrivingDate: '', // '首次行驶时间',
        // firstOnlineDisplayMileage: '', // '首次上线表显里程',
        fullChargedDrivingMile: '', // '当前满电续驶里程',
        lastDrivingDate: '', // '最近一次行驶时间',
        usageDate: '', // '已使用时间',
        displayMileage: '', // '表显行驶里程',
        yearAvgMileage: '', // '年平均里程',
        averageDailyDriveHour: '', // '日均行驶时长',
        averageDailyUseHour: '', // '日均用车时长',
        powerConsumptionPer: '', // '百公里耗电量',
        optimumTempPro: '', // '舒适温度运行占比',
        driveStartSoc: '', // '行车最高频率下的起始SOC',
        driveEndSoc: '', // '行车最高频率下的截止SOC',
        driveMaxTempMean: '', // '行驶最高温度平均',
        driveMinTempMean: '' // '行驶最低温度平均',
        // chaStartSoc: '' // '充电截止温度（高频）'
    })
    //电池安全分析
    BATTERY_SAFE_abnormal = ref(0)
    BATTERY_SAFE = reactive<basicParams>({
        abnormalA: '', // '一级故障水平',
        abnormalB: '', // '二级故障水平',
        abnormalC: '', // '三级级故障水平',
        batteryThermalManage: '', // '热管理水平',
        voltManage: '', // '电压管理水平',
        powerManage: '', // '电量管理水平',
        voltConsistManage: '', // '电压一致性管理水平',
        insulateManage: '', // '绝缘管理水平',
        dcdcManage: '', // 'DC-DC管理水平',
        motorThermalManage: '', // '电机热管理水平',
        otherManage: '' // '其他管理水平'
    })
    //疑似行为检查
    SUSPECTED_BEHAVIOR = reactive({
        suspectedAdjust: '', // '是否疑似调表',
        suspectedAdjustDate: '', // '疑似调表时间',
        suspectedMileageAfterAdjust: '', // '疑似调表后里程',
        suspectedMileageBeforeAdjust: '' // '疑似调表前里程'
    })
    //评分说明弹窗
    scoreExplainDialog = reactive({
        visible: false
    })
    //监听滚动元素
    scrollEl: any
    //屏幕的高度
    windowHeight = 0
    //内容区域高度
    contentHeight = 0
    //对应的栏目是否展开
    columnArray = reactive<columnParams[]>([
        {
            key: '',
            blockClassName: '',
            bodyClassName: '',
            name: '出险排查',
            icon: false,
            hint: '红色表示异常，其他则为正常',
            abnormal: false,
            abnormalCount: 0,
            spread: true
        },
        {
            key: '',
            blockClassName: 'battery-score-block',
            bodyClassName: '',
            name: '电池健康度评分',
            icon: true,
            hint: '',
            abnormal: true,
            abnormalCount: 0,
            spread: true
        },
        {
            key: '',
            blockClassName: 'endurance-block',
            bodyClassName: '',
            name: '电池静态数据',
            icon: false,
            hint: '',
            abnormal: false,
            abnormalCount: 0,
            spread: true
        },
        {
            key: '',
            blockClassName: 'charge-discharge-block',
            bodyClassName: '',
            name: '充放电数据',
            icon: false,
            hint: '',
            abnormal: true,
            abnormalCount: 0,
            spread: true
        },
        {
            key: '',
            blockClassName: 'run-block',
            bodyClassName: '',
            name: '行驶数据',
            icon: false,
            hint: '',
            abnormal: true,
            abnormalCount: 0,
            spread: true
        },
        {
            key: '',
            blockClassName: 'battery-safe-block',
            bodyClassName: '',
            name: '电池安全分析',
            icon: false,
            hint: '',
            abnormal: true,
            abnormalCount: 0,
            spread: true
        },
        {
            key: '',
            blockClassName: '',
            bodyClassName: '',
            name: '疑似行为检查',
            icon: false,
            hint: '',
            abnormal: false,
            abnormalCount: 0,
            spread: true
        }
    ])
    //报告查询失败
    reportQueryFail = ref(false)
    //报告评分等级
    scoreLevel = ref(0)
    constructor() {
        const router = useRoute()
        this.reportId.value = router.query.reportId as string
        this.vinParseId.value = router.query.vinParseId as string
        if (router.query.share as string) {
            this.isShare.value = true
        }
        const type = ref('')
        type.value = (router.query.type as string) ?? ''
        this.fromCase.value = type.value ? true : false
        this.reportType.value = router.query.productType as string

        this.windowHeight = window.innerHeight

        Promise.all([
            vinParse(this.vinParseId.value), //vin码解析数据查询
            getReportBatteryDetailed(this.reportId.value) //报告详细信息
        ]).then(res => {
            if (res[1].data.value === 7003) {
                ///报告过期
                this.reportExpire.value = true
            } else if (res[0].data.value !== 200 && res[1].data.value !== 200) {
                this.reportQueryFail.value = true
            }
            //vin 解析返回的数据
            let vinParseResult = null
            if (res[0].data.value === 200) {
                vinParseResult = res[0].data.data
                console.log('vin 解析返回的数据', vinParseResult)
                //vin
                this.baseInfo.vin = vinParseResult.vin
                //车型
                this.baseInfo.models = vinParseResult.modelDetail
            }

            if (res[1].data.value === 200) {
                //报告数据
                const batteryDetails = res[1].data.data.batteryDetails
                //报告的vin数据
                const reportDetails = res[1].data.data.reportDetails

                console.log('vin 解析返回的数据', vinParseResult)
                /**
                 * 报告基本信息
                 */
                this.baseInfo.orderNo = reportDetails.orderNo
                this.baseInfo.reportNo = reportDetails.reportNo
                //报告生成时间
                this.baseInfo.generateTime = reportDetails.generateTime
                //车牌号
                this.baseInfo.plateNo = reportDetails.plateNo
                //vin
                this.baseInfo.vin = reportDetails.vin

                //车标
                this.baseInfo.brandLogo = vinParseResult.brandLogo || reportDetails.brandNameUrl
                //车牌颜色 (1.绿牌；2.蓝牌；3.其他)
                this.baseInfo.licensePlateColor = vinParseResult.licensePlateColor + ''
                //车型
                this.baseInfo.models = vinParseResult.modelDetail || reportDetails.model
                //品牌
                this.baseInfo.brandname = vinParseResult.brand || reportDetails.brandName
                //动力类型
                this.baseInfo.fuelType = vinParseResult.fuelType
                //排量
                this.baseInfo.displacement = vinParseResult.displacement
                //上市时间
                this.baseInfo.listingTime = vinParseResult.listingTime

                //电池评分
                //内阻
                this.score.push(this.setBatteryHealthScore('内阻', Number(batteryDetails.internalResistanceScore)))
                //温度一致性
                this.score.push(
                    this.setBatteryHealthScore('温度一致性', Number(batteryDetails.temperatureConsistenceScore))
                )
                //电压一致性
                this.score.push(this.setBatteryHealthScore('电压一致性', Number(batteryDetails.voltConsistenceScore)))
                //自放电率
                this.score.push(this.setBatteryHealthScore('自放电率', Number(batteryDetails.selfDischargeRateScore)))
                //容量保持率
                this.score.push(this.setBatteryHealthScore('容量保持率', Number(batteryDetails.volumeScore)))
                console.log('this.score', this.score)
                //电池异常数
                this.score.forEach(item => {
                    if (item.value < 80) {
                        //小于80算异常
                        this.BATTERY_Score_abnormal.value++
                    }
                })
                //出险排查异常项
                this.checkList[0].value = this.BATTERY_Score_abnormal.value
                this.columnArray[1].abnormalCount = this.BATTERY_Score_abnormal.value

                /**
                 * 电池静态数据
                 */
                //参考续航里程
                this.BATTERY_STATIC_DATA.fullChargedDrivingMile = batteryDetails.fullChargedDrivingMile + 'km'
                //电池厂商
                this.BATTERY_STATIC_DATA.batteryManufacturer = batteryDetails.batteryManufacturer
                //标称电池容量
                this.BATTERY_STATIC_DATA.rateCapacity = batteryDetails.rateCapacity + 'Ah'
                //电池包编码
                this.BATTERY_STATIC_DATA.packCode = batteryDetails.packCode
                //标称续航里程
                this.BATTERY_STATIC_DATA.rateMileage = batteryDetails.rateMileage + 'km'
                //系统标称能量
                this.BATTERY_STATIC_DATA.nominalEnergy = batteryDetails.nominalEnergy + 'kwh'
                //生产日期
                this.BATTERY_STATIC_DATA.manufacturerDate = batteryDetails.manufacturerDate

                /**
                 * 充放电数据
                 */
                //首次充电时间
                this.CHARGE_DISCHARGE_DATA.firstChargeDate = batteryDetails.firstChargeDate
                //最后一次充电时间
                this.CHARGE_DISCHARGE_DATA.latestChargeDate = batteryDetails.latestChargeDate
                //总充电次数
                this.CHARGE_DISCHARGE_DATA.totalChargeCount = batteryDetails.totalChargeCount
                //估计的充电次数
                this.CHARGE_DISCHARGE_DATA.estimatedChargeCount = batteryDetails.estimatedChargeCount
                //总充电量以循环圈数累计
                this.CHARGE_DISCHARGE_DATA.totalChargeSoc = batteryDetails.totalChargeSoc
                //充电电芯平均压差 =>超过50，异常显示文案“偏高”
                this.CHARGE_DISCHARGE_DATA.chaVoltDiffMean = this.disposeData(
                    Number(batteryDetails.chaVoltDiffMean),
                    50,
                    'mv',
                    true
                )
                //快充占比 =>超过75%，异常显示文案“偏高”
                this.CHARGE_DISCHARGE_DATA.fastRatio = this.disposeData(
                    Number(batteryDetails.fastRatio) * 100,
                    75,
                    '%',
                    true
                )

                //均次充入量 =>低于75%，异常显示文案“偏低”
                this.CHARGE_DISCHARGE_DATA.chaSocAvg = this.disposeData(Number(batteryDetails.chaSocAvg), 75, '%', true)
                //充电最高温度平均 =>高于45度，异常显示文案“偏高”
                this.CHARGE_DISCHARGE_DATA.chaMaxTempMean = this.disposeData(
                    Number(batteryDetails.chaMaxTempMean),
                    45,
                    '°C',
                    true
                )
                //充电最低温度平均 =>高于30度，异常显示文案“偏高”
                //充电最低温度平均 =>低于-5度，异常显示文案“偏低”
                const chaMinTempMean = Number(batteryDetails.chaMinTempMean)
                this.CHARGE_DISCHARGE_DATA.chaMinTempMean = {
                    value: chaMinTempMean + '°C',
                    status: chaMinTempMean >= 35 || chaMinTempMean <= -5 ? 1 : 0,
                    label: chaMinTempMean >= 35 ? '偏高' : chaMinTempMean <= -5 ? '偏低' : ''
                }
                //充电起始电量(高频) =>开始值超过70%，异常显示文案“偏高”
                const chaStartSoc = batteryDetails.chaStartSoc.split('-')
                this.CHARGE_DISCHARGE_DATA.chaStartSoc = {
                    value: Number(chaStartSoc[0]) >= 70 ? chaStartSoc[0] : chaStartSoc[0] + '%-' + chaStartSoc[1] + '%',
                    status: Number(chaStartSoc[0]) >= 70 ? 1 : 0,
                    label: Number(chaStartSoc[0]) >= 70 ? '偏高' : ''
                }
                //充电最高频率下的截止SOC
                const chaEndSoc = batteryDetails.chaEndSoc.split('-')
                this.CHARGE_DISCHARGE_DATA.chaEndSoc = chaEndSoc[0] + '%-' + chaEndSoc[1] + '%'

                /**
                 * 行驶数据
                 */
                //首次行驶时间
                this.RUN_DATA.firstDrivingDate = batteryDetails.firstDrivingDate
                //首次上线表显里程
                this.RUN_DATA.firstOnlineDisplayMileage = Number(batteryDetails.firstOnlineDisplayMileage) / 10 + 'km'
                //当前满电续驶里程
                this.RUN_DATA.fullChargedDrivingMile = batteryDetails.fullChargedDrivingMile + 'km'
                //最近一次行驶时间
                this.RUN_DATA.lastDrivingDate = batteryDetails.lastDrivingDate
                //已使用时间
                this.RUN_DATA.usageDate = dayToDate(batteryDetails.usageDate)
                //表显行驶里程 =>取字段suspectedAdjust是否调表，若字段返回调表，异常文案显示“疑似调表”
                this.RUN_DATA.displayMileage = {
                    value: Number(batteryDetails.displayMileage) / 10 + 'km',
                    status: batteryDetails.suspectedAdjust ? 1 : 0,
                    label: batteryDetails.suspectedAdjust ? '疑似调表' : ''
                }
                //表显行驶里程
                this.RUN_DATA.yearAvgMileage = Number(batteryDetails.yearAvgMileage) / 10 + 'km'
                //年平均里程
                this.RUN_DATA.averageDailyDriveHour = batteryDetails.averageDailyDriveHour + 'h'
                //日均行驶时长
                this.RUN_DATA.averageDailyUseHour = batteryDetails.averageDailyUseHour + 'h'
                //百公里耗电量
                this.RUN_DATA.powerConsumptionPer = vinParseResult.powerConsumptionPer
                // this.RUN_DATA.powerConsumptionPer =
                //     ((batteryDetails.nominalEnergy * 100) / batteryDetails.fullChargedDrivingMile).toFixed(1) + 'kwh/100km'
                //舒适温度运行占比 =>低于50%，异常显示文案“偏低”
                this.RUN_DATA.optimumTempPro = this.disposeData(
                    Number(batteryDetails.optimumTempPro) * 100,
                    50,
                    '%',
                    false
                )
                //行车最高频率下的截止SOC =>截止值小于50%，异常显示文案“异常”
                const driveStartSoc = batteryDetails.driveStartSoc.split('-')
                this.RUN_DATA.driveStartSoc = {
                    value:
                        Number(driveStartSoc[0]) <= 50
                            ? driveStartSoc[0]
                            : driveStartSoc[0] + '%-' + driveStartSoc[1] + '%',
                    status: Number(driveStartSoc[0]) <= 50 ? 1 : 0,
                    label: Number(driveStartSoc[0]) <= 50 ? '异常' : '',
                    icon: Number(driveStartSoc[0]) <= 50 ? 0 : null
                }

                //行车最高频率下的截止SOC =>截止值小于50%，异常显示文案“异常”
                const driveEndSoc = batteryDetails.driveEndSoc.split('-')
                this.RUN_DATA.driveEndSoc = {
                    value: Number(driveEndSoc[0]) <= 50 ? driveEndSoc[0] : driveEndSoc[0] + '%-' + driveEndSoc[1] + '%',
                    status: Number(driveEndSoc[0]) <= 50 ? 1 : 0,
                    label: Number(driveEndSoc[0]) <= 50 ? '异常' : '',
                    icon: Number(driveEndSoc[0]) <= 50 ? 0 : null
                }
                //行驶最高温度平均 =>高于45度，异常显示文案“偏高”
                this.RUN_DATA.driveMaxTempMean = this.disposeData(
                    Number(batteryDetails.driveMaxTempMean),
                    45,
                    '°C',
                    true
                )

                //行驶最低温度平均 =>高于30度，异常显示文案“偏高”
                //行驶最低温度平均 =>低于-5度，异常显示文案“偏低”
                const driveMinTempMean = Number(batteryDetails.driveMinTempMean)
                this.RUN_DATA.driveMinTempMean = {
                    value: driveMinTempMean + '°C',
                    status: driveMinTempMean >= 30 || driveMinTempMean <= -5 ? 1 : 0,
                    label: driveMinTempMean >= 30 ? '偏高' : driveMinTempMean <= -5 ? '偏低' : '',
                    icon: driveMinTempMean >= 30 ? 1 : driveMinTempMean <= -5 ? 0 : null
                }

                // this.RUN_DATA.chaStartSoc = chaStartSoc[0] + '%-' + chaStartSoc[1] + '%'

                /**
                 * 电池安全分析
                 */
                //一级故障水平
                this.BATTERY_SAFE.abnormalA = this.battrySafeAanlyse(batteryDetails.abnormalA)
                //二级故障水平
                this.BATTERY_SAFE.abnormalB = this.battrySafeAanlyse(batteryDetails.abnormalB)
                //三级级故障水平
                this.BATTERY_SAFE.abnormalC = this.battrySafeAanlyse(batteryDetails.abnormalC)
                //热管理水平
                this.BATTERY_SAFE.batteryThermalManage = this.battrySafeAanlyse(batteryDetails.batteryThermalManage)
                //电压管理水平
                this.BATTERY_SAFE.voltManage = this.battrySafeAanlyse(batteryDetails.voltManage)
                //电量管理水平
                this.BATTERY_SAFE.powerManage = this.battrySafeAanlyse(batteryDetails.powerManage)
                //电压一致性管理水平
                this.BATTERY_SAFE.voltConsistManage = this.battrySafeAanlyse(batteryDetails.voltConsistManage)
                //绝缘管理水平
                this.BATTERY_SAFE.insulateManage = this.battrySafeAanlyse(batteryDetails.insulateManage)
                //DC-DC管理水平
                this.BATTERY_SAFE.dcdcManage = this.battrySafeAanlyse(batteryDetails.dcdcManage)
                //电机热管理水平
                this.BATTERY_SAFE.motorThermalManage = this.battrySafeAanlyse(batteryDetails.motorThermalManage)
                //其他管理水平
                this.BATTERY_SAFE.otherManage = this.battrySafeAanlyse(batteryDetails.otherManage)

                /**
                 * 疑似行为检查
                 */
                //是否疑似调表
                this.SUSPECTED_BEHAVIOR.suspectedAdjust = batteryDetails.suspectedAdjust ? '是' : '否'
                //疑似调表时间
                this.SUSPECTED_BEHAVIOR.suspectedAdjustDate = batteryDetails.suspectedAdjustDate
                //疑似调表后里程
                this.SUSPECTED_BEHAVIOR.suspectedMileageAfterAdjust = batteryDetails.suspectedMileageAfterAdjust
                //疑似调表前里程
                this.SUSPECTED_BEHAVIOR.suspectedMileageBeforeAdjust = batteryDetails.suspectedMileageBeforeAdjust

                //初始化电池评分
                // new AnalysisChart('.score-container', this.score)

                //初始化续航
                new DialGaugeChart(
                    '.endurance-container',
                    Number(batteryDetails.fullChargedDrivingMile) / Number(batteryDetails.rateMileage)
                )

                // 当前工况参考续航里程下降
                this.declineRatio.value = (
                    (1 - Number(batteryDetails.fullChargedDrivingMile) / Number(batteryDetails.rateMileage)) *
                    100
                ).toFixed(1)

                //充放电数据异常统计
                for (const key in this.CHARGE_DISCHARGE_DATA) {
                    if (
                        Object.prototype.toString.call(this.CHARGE_DISCHARGE_DATA[key]) === '[object Object]' &&
                        (this.CHARGE_DISCHARGE_DATA[key] as objParams).status === 1
                    ) {
                        this.CHARGE_DISCHARGE_DATA_abnormal.value++
                    }
                }
                //出险排查 - 电池健康度 异常数
                this.checkList[1].value = this.CHARGE_DISCHARGE_DATA_abnormal.value
                this.columnArray[3].abnormalCount = this.CHARGE_DISCHARGE_DATA_abnormal.value

                //行驶数据异常统计
                for (const key in this.RUN_DATA) {
                    if (
                        Object.prototype.toString.call(this.RUN_DATA[key]) === '[object Object]' &&
                        (this.RUN_DATA[key] as objParams).status === 1
                    ) {
                        this.RUN_DATA_abnormal.value++
                    }
                }
                console.log('RUN_DATA', this.RUN_DATA)
                //出险排查 - 充放电数据 异常数
                this.checkList[2].value = this.RUN_DATA_abnormal.value
                this.columnArray[4].abnormalCount = this.RUN_DATA_abnormal.value

                //故障分析异常统计
                for (const key in this.BATTERY_SAFE) {
                    if ((this.BATTERY_SAFE[key] as any[])[1] === 3) {
                        this.BATTERY_SAFE_abnormal.value++
                    }
                }
                //出险排查 - 故障分析 异常数
                this.checkList[3].value = this.BATTERY_SAFE_abnormal.value
                this.columnArray[5].abnormalCount = this.BATTERY_SAFE_abnormal.value

                const totalScore = new NewEnergyScore().init(batteryDetails)

                console.log('最后得分', totalScore)
                if (totalScore >= 95) {
                    console.log('优', 'S')
                    this.scoreLevel.value = 1
                } else if (totalScore >= 80 && totalScore < 95) {
                    console.log('良', 'A')
                    this.scoreLevel.value = 2
                } else if (totalScore >= 65 && totalScore < 80) {
                    console.log('中', 'B')
                    this.scoreLevel.value = 3
                } else {
                    console.log('差', 'C')
                    this.scoreLevel.value = 4
                }

                //报告加载完成
                this.reportLoad.value = true

                //分享设置
                if (!this.fromCase.value) {
                    useWeixinSdk.shareReport({
                        title:
                            this.baseInfo.plateNo && this.baseInfo.plateNo.length > 6
                                ? this.baseInfo.plateNo + '的车况报告'
                                : this.baseInfo.brandname + '车型的车况报告',
                        desc: `vin：${this.baseInfo.vin}\r\n生成时间：${this.baseInfo.generateTime}`,
                        link: window.location.href + '&share=true',
                        imgUrl: this.baseInfo.brandLogo
                    })
                }
            }
        })

        onMounted(() => {
            setTimeout(() => {
                this.watermarkVisible.value = true
            }, 100)

            //区分是否从分享进入
            if (this.isShare.value) {
                //分享进入不可再分享
                useWeixinSdk.disableShare()
            } else {
                useWeixinSdk.ableShare()
            }

            if (!this.reportQueryFail.value) {
                this.scrollEl = document.querySelector('.report-main') as HTMLElement
                this.contentHeight = (document.querySelector('#report') as HTMLElement).offsetHeight
                this.scrollEl?.addEventListener('scroll', this.onScroll, false)
            }
        })

        onUnmounted(() => {
            this.scrollEl?.addEventListener('scroll', this.onScroll, false)
        })
    }
    /**
     * 根据传入的值判断
     * @param n
     * @returns
     */
    battrySafeAanlyse = (n: number | string) => {
        let text = ''
        let m = 0
        if (Number(n) === -1) {
            text = '没有上传过异常数据'
            m = -1
        } else if (Number(n) >= 0 && Number(n) < 0.5) {
            text = '观察期内无故障报警'
            m = 0
        } else if (Number(n) >= 0.5 && Number(n) < 1.5) {
            text = `报警是同车型均值的${n}倍`
            m = 1
        } else if (Number(n) >= 0 && Number(n) < 3) {
            text = `报警是同车型均值的${n}倍`
            m = 2
        } else if (Number(n) >= 3) {
            text = `报警是同车型均值的${n}倍`
            m = 3
            this.BATTERY_SAFE_abnormal.value++
        }
        return [text, m]
    }
    setBatteryHealthScore = (name: string, score: number) => {
        const obj = {
            name,
            value: score,
            label: 0
        }
        batteryHealthScore.some((item: any, index: number) => {
            const b = 0
            if (Object.prototype.toString.call(item.range) === '[object Array]') {
                obj.label = score > item.range[0] && score <= item.range[1] ? index : 0
            } else if (Object.prototype.toString.call(item.range) === '[object Object]') {
                if ('min' in item.range) {
                    if (item.range.min > score) {
                        obj.label = index
                    }
                }
            }
            return b
        })
        return obj
    }
    /**
     *
     * @param val 当前输入值
     * @param threshold 目标阈值
     * @param unit 单位
     * @param greater true大于 false小于
     * @returns
     */
    disposeData(val: number, threshold: number, unit: string, greater: boolean) {
        const obj: objParams = { value: val + unit, status: 0, label: '', icon: null }
        if (greater) {
            obj.status = val >= threshold ? 1 : 0
            obj.label = val >= threshold ? '偏高' : ''
            obj.icon = val >= threshold ? 1 : null
        } else {
            obj.status = val <= threshold ? 1 : 0
            obj.label = val <= threshold ? '偏低' : ''
            obj.icon = val <= threshold ? 1 : null
        }
        return obj
    }
    //监听滚动
    onScroll = () => {
        if (this.scrollEl?.scrollTop >= this.windowHeight / 2) {
            //大于屏幕的一半
            //返回顶部按钮出现
            if (!this.goTopVisible.value) {
                this.goTopVisible.value = true
            }
        } else {
            if (this.goTopVisible.value) {
                this.goTopVisible.value = false
            }
        }

        if (this.scrollEl?.scrollTop >= this.contentHeight - this.windowHeight * 1.5 && !this.fromCase.value) {
            //底部按钮出现
            if (!this.bottomFnVisible.value) {
                this.bottomFnVisible.value = true
            }
        } else {
            if (this.bottomFnVisible.value) {
                this.bottomFnVisible.value = false
            }
        }
    }
    //返回顶部
    goTop = () => {}
    //下载报告-显示保存图片弹窗
    startDownload = () => {
        //所有栏目默认展开
        this.columnArray.forEach((item: columnParams) => {
            item.spread = true
        })
    }
    //点击隐藏下载弹窗
    hideDownload = () => {}
    //
    onVisibleScoreExplainDialog = (type: string) => {
        if (type === 'show') {
            this.scoreExplainDialog.visible = true
        } else if (type === 'hide') {
            this.scoreExplainDialog.visible = false
        }
    }
    //点击 滚动 到指定位置
    onSkipAnchor(eleName: string) {
        if (!eleName) {
            return
        }
        const targetEle = document.querySelector(eleName) as HTMLElement
        if (!targetEle) {
            return
        }

        scrollIntoView(targetEle, {
            behavior: instructions => {
                const [{ el, top }] = instructions
                const styler = Styler(el)

                animate({
                    from: el.scrollTop,
                    to: top - 10,
                    type: 'keyframes',
                    onUpdate: (y: number) => styler.set('scrollTop', y)
                })
            },
            block: 'start',
            inline: 'end'
        })
    }
    //信息项是否展开 1 基本信息 2 配置信息
    toggle = (index: number) => {
        this.columnArray[index].spread = !this.columnArray[index].spread
        nextTick(() => {
            this.contentHeight = (document.querySelector('#report') as HTMLElement).offsetHeight
        })
    }
}
